package com.wu.ssm.mybatis;

import org.springframework.beans.factory.InitializingBean;

/**
 * spring-mybatis初始化类
 * Created by wzf on 2018/11/21/021.
 */
public class SqlSessionFactoryBean implements InitializingBean {

    private MySqlSessionFactory sqlSessionFactory;

    @Override
    public void afterPropertiesSet() throws Exception {

        this.sqlSessionFactory = buildSqlSessionFactory();
    }

    protected MySqlSessionFactory buildSqlSessionFactory() {

        MyConfiguration configuration;

        //读取xml文件并放置configuration。mappedStatements
        //xmlConfigBuilder.parse();
        configuration = new MyConfiguration();
        configuration.mappedStatements.put("getUserById","SELECT * FROM USER WHERE id =?");

        MySqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }

}
